<?php
/**
 *
 * @user: leo
 * @date: 2021/6/22
 * @createTime: 15:15
 * @company: 迈酷网络科技 http://www.maicooit.com
 */
namespace app\admin\controller\user;

use app\controller\Response;
use app\admin\logic\user\Domains as DomainsLogic;
use app\BaseController;

class Domains extends BaseController{
    /**
     * @OA\Get(
     *   path="/admin/user/domainList",
     *   tags={"用户相关接口"},
     *   summary="租户列表",
     *   @OA\Parameter(name="key", in="query", description="关键词", @OA\Schema(type="string")),
     *   @OA\Parameter(name="page", in="query", description="页码", @OA\Schema(type="string")),
     *   @OA\Parameter(name="pagesize", in="query", description="每页数量", @OA\Schema(type="string")),
     *   @OA\Response(
     *     response=200,
     *     description="A list with products"
     *   )
     * )
     */
    public function domainList($key="",$page=1,$pagesize=10){
        try{
            $list = DomainsLogic::DomainsListLogic($key,$page,$pagesize);
            if($list){
                $res = Response::succJson($list,0,'获取数据成功！');
                return json($res);
            }else{
                $res = Response::errJson('',200,'获取数据失败！');
                return json($res);
            }
        }catch (\Exception $e){
            $res = Response::errJson('',$e->getCode(),$e->getMessage());
            return json($res);
        }
    }
    /**
     * @OA\Post(
     *   path="/admin/user/domainAdd",
     *   tags={"用户相关接口"},
     *   summary="租户新增",
     *   @OA\RequestBody(
     *     @OA\MediaType(
     *       mediaType="content-type/json",
     *         @OA\Schema(
     *           @OA\Property(description="租户代码", property="domain_area_code", type="string"),
     *           @OA\Property(description="租户组织名称", property="domain_area_orgname", type="string"),
     *           required={"domain_area_code,domain_area_orgname"})
     *       )
     *     ),
     *   @OA\Response(
     *     response=200,
     *     description="A list with products"
     *   )
     * )
     */
    public function domainAdd(){
        try{
            $domainInfo = request()->post();
            $list = DomainsLogic::DomainsAddLogic($domainInfo);
            if($list){
                $res = Response::succJson($list,0,'添加成功！');
                return json($res);
            }else{
                $res = Response::errJson('',200,'添加失败！');
                return json($res);
            }
        }catch (\Exception $e){
            $res = Response::errJson('',$e->getCode(),$e->getMessage());
            return json($res);
        }
    }
}